//
//  GYModfiyPWDView.m
//  LockManagement
//
//  Created by apple on 2018/7/24.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

#import "GYModfiyPWDView.h"

@interface GYModfiyPWDView()

@property (weak, nonatomic) IBOutlet UITextField *NPassWorldTF;
@property (weak, nonatomic) IBOutlet UITextField *confirmPwdTF;
@property (weak, nonatomic) IBOutlet UIButton *confirmBtn;
@property (weak, nonatomic) IBOutlet UIButton *cancelBtn;

@property (weak, nonatomic) IBOutlet UIView *modfiyView;

@end

@implementation GYModfiyPWDView

- (void)awakeFromNib {
    [super awakeFromNib];
    self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.4];
    [self setBtnAttribute:self.confirmBtn];
    [self setBtnAttribute:self.cancelBtn];
    self.modfiyView.layer.cornerRadius = 5;
    self.modfiyView.layer.masksToBounds = YES;
    
    //给TF添加右下角按钮点击事件
    [self.NPassWorldTF addTarget:self action:@selector(TFendEdit) forControlEvents:UIControlEventEditingDidEndOnExit];
    [self.confirmBtn addTarget:self action:@selector(TFendEdit) forControlEvents:UIControlEventEditingDidEndOnExit];
}

- (void)TFendEdit {
    [self endEditing:YES];
}

- (IBAction)btnClcik:(UIButton *)sender {
    //1代表确认  2代表取消
    if (sender.tag == 1) {
        //判断密码是不是一样
        if (self.NPassWorldTF.text.length == 0 || [self.NPassWorldTF.text isEqualToString:@""]) {
            [SVProgressHUD showInfoWithStatus:@"密码不能空!"];
            return;
        }
        if (![self.NPassWorldTF.text isEqualToString:self.confirmPwdTF.text]) {
            [SVProgressHUD showInfoWithStatus:@"两次输入的密码不一样!"];
            return;
        }
        self.confirmModfiyPassWordCallBack(self.NPassWorldTF.text);
    }else {
        [self removeFromSuperview];        
    }
}

- (void)setBtnAttribute:(UIButton *)btn {
    btn.layer.cornerRadius = 5;
    btn.layer.borderWidth = 1;
    btn.layer.borderColor = RGBColor(187, 187, 187).CGColor;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self endEditing:YES];
}
@end
